package crafex.engine.system;

import crafex.engine.level.Level;
import crafex.engine.tools.Tools;

import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.AssetManager;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;

public abstract class App extends Activity {
	
	public static Tools tools;
	public static AssetManager assets;
	protected int width;
	protected int height;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Display display = getWindowManager().getDefaultDisplay();
        
        width = display.getWidth();
    	height = display.getHeight();
        
        startUp();
    }
    
    public abstract void startUp();
    
    public void init(SharedPreferences settings, App app, Level defaultLevel, AssetManager assets, boolean gameMode){
    	
    	if(gameMode){
    		requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            		WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    	}
    	
    	tools = new Tools(getFilesDir().toString());
    	
        App.assets = assets;
        
    	setContentView(new Crafex(app, this, settings, assets, defaultLevel, width, height));
    }
}
